<template>
  <div class="container">
    <van-nav-bar title="登录"/>
    <div class="main">
      <div class="top">
        <img class="top-img" src="../assets/img/login/login-top.png" alt>
        <div class="text">智慧党建</div>
      </div>
      <div class="form">
        <van-cell-group>
          <van-field v-model="username" left-icon="manager" placeholder="请输入手机号或账号"/>
          <van-field v-model="password" type="password" left-icon="lock" placeholder="请输入密码"/>
          <!-- <van-field v-model="captcha" center clearable label="验证码" placeholder="请输入短信验证码">
            <img
              class="code-img"
              slot="button"
              :src="`http://39.106.139.151:7676/xbkj-dj/web/captcha.jpg?uuid=${uuid}`"
              alt
              srcset
            >
          </van-field>-->
        </van-cell-group>
      </div>
      <div class="btns">
        <div class="btn login" @click="onLogin">登录</div>
        <!-- <div class="btn register">注册</div> -->
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      username: '',
      password: '',
      uuid: new Date().getTime()
    }
  },
  methods: {
    onLogin () {
      const { username, password } = this
      if (!username) {
        this.$toast('请输入账号')
        return
      }
      if (!password) {
        this.$toast('请输入密码')
        return
      }
      this.$axios
        .post('/xbkj-dj/web/login', {
          username,
          password
        })
        .then(res => {
          console.log(res)
          if (res.code === 0) {
            console.log(res.token)
            window.localStorage.setItem('token', res.token)
            this.$toast('登录成功')
            this.$router.push('/index')
          }
        })
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  background-color: #fff;
}
.van-nav-bar {
  background-color: #f14531;
  border: none;
  /deep/ .van-nav-bar__title {
    color: #fff;
  }
}
.van-hairline--bottom::after {
  border: none;
}
.main {
  background-color: #fff;
  .btns {
    padding: 30px 40px;
    .btn {
      width: 100%;
      height: 40px;
      line-height: 40px;
      text-align: center;
      border-radius: 20px;
      border: 1px solid #f0321d;
      &.login {
        background-color: #f0321d;
        color: #fff;
        margin-bottom: 20px;
      }
      &.register {
        background-color: #fff;
        color: #f24d3b;
        border-color: #f24d3b;
      }
    }
  }
  .top {
    position: relative;
    margin-bottom: 10px;
    .top-img {
      display: block;
      width: 100%;
    }
    .text {
      position: absolute;
      top: 40%;
      left: 50%;
      transform: translate(-50%, -50%);
      color: #fff;
      font-size: 24px;
    }
  }
  .form {
    padding: 20px;
    background-color: #fff;
    /deep/ .van-cell {
      padding: 15px;
      .van-icon {
        color: #f7988e;
      }
    }
    /deep/ .van-hairline--top-bottom::after {
      border-width: 0 0 1px 0;
      left: 15px;
      right: 0;
      bottom: 0;
      transform: scaleY(0.5);
      border-bottom: 1px solid #ebedf0;
      top: auto;
      bottom: 0;
    }
  }
}
.code-img {
  display: block;
  width: 40px;
  height: 20px;
}
</style>
